import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/channel/acAuth/list',
  save='/baseinfo/ssPerson/add',
  edit='/baseinfo/ssPerson/edit',
  freeze = '/baseinfo/ssPerson/freeze',
  unfreeze = '/baseinfo/ssPerson/unfreeze',
  deleteOne = '/baseinfo/ssPerson/delete',
  deleteBatch = '/baseinfo/ssPerson/deleteBatch',
  importExcel = '/baseinfo/ssPerson/importExcel',
  exportXls = '/baseinfo/ssPerson/exportXls',
  exportTemplateXls = "/baseinfo/ssPerson/exportTemplateXls",
  importPhoto = "/baseinfo/ssPerson/importPhoto",
  deviceList = '/baseinfo/ssDevice/list',
  deviceResultList = '/channel/acAuth/devlist',
  ruleList = '/channel/acRuleChannel/queryRuleByChannelId',
  addAuth = '/channel/acAuth/add',
  editAuth = '/channel/acAuth/edit',
  queryById = '/channel/acAuth/queryById',
  deleteBatchAuth = '/channel/acAuth/deleteBatch',
  channelList = '/channel/ssChannel/list',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
export const getExportTemplateUrl = Api.exportTemplateXls;
export const getImportPhotoUrl = Api.importPhoto;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) => {
  return defHttp.get({url: Api.list, params});
}

export const deviceResultList = (params) => {
  return defHttp.get({url: Api.deviceResultList, params});
}

export const deviceList = (params) => {
  return defHttp.get({url: Api.deviceList, params});
}

export const ruleList = (params) => {
  return defHttp.get({url: Api.ruleList, params});
}

export const queryById = (params) => {
  return defHttp.get({url: Api.queryById, params});
}

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    },
  });
}

/**
 * 批量删除
 * @param params
 */
export const deleteBatchAuth = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认撤权',
    content: '是否撤权选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.post({url: Api.deleteBatchAuth, data: params},).then(() => {
        handleSuccess();
      });
    },
  });
}

export const freeze = (params, handleSuccess) => {
      return defHttp.post({url: Api.freeze, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
}
export const unfreeze = (params, handleSuccess) => {
  return defHttp.post({url: Api.unfreeze, data: params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

export const addRuleApi = (params) => {
  return defHttp.post({url: Api.addAuth, data: params},).then(() => {
  });
}

export const editRuleApi = (params) => {
  return defHttp.post({url: Api.editAuth, data: params},).then(() => {
  });
}


/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}
